﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ElFinder.Connector.Utils;
namespace ElFinder.Connector.Commands
{
    public class Edit : ICommand
    {
        public string Target { get; set; }

        public string Current { get; set; }

        public string Content { get; set; }

        public Edit(string current, string target, string content)
        {
            this.Target = target;
            this.Current = current;
            this.Content = content;  
        }

        #region ICommand Members       

        public ElFinder.Connector.Responses.Response Execute()
        {
            //var path = DirectoryUtils.GetRelativePathByHash(Current);

            var toEdit = DirectoryUtils.GetFilePathByHash(Target);
            System.IO.File.WriteAllText(toEdit, Content);
            System.IO.FileInfo f = new System.IO.FileInfo(toEdit);

            var response = new Responses.FileResponse();

            response.file = new Cdc(f);

            return response;
        }

        #endregion
    }
}
